package com.y.architecture.activity;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.view.MenuItem;
import android.view.View;

import com.y.architecture.R;
import com.y.architecture.base_net.ApiCallback;
import com.y.architecture.base_refresh_load.BaseRefreshLoadActivity;
import com.y.architecture.recycle_util.BaseQuickAdapter;
import com.y.architecture.recycle_util.BaseViewHolder;
import com.y.architecture.util.AFConstant;
import com.y.architecture.weather.Weather;
import com.y.architecture.weather.WeatherService;

import butterknife.BindView;

public class MenuActivity extends BaseRefreshLoadActivity<Weather.HeWeather6Bean> implements BaseQuickAdapter.OnItemLongClickListener {

    @BindView(R.id.bottom_navigation)
    BottomNavigationView bottomNavigationView;

    @Override
    public int getContentView() {
        return R.layout.activity_menu;
    }

    @Override
    public void initViews(Bundle savedInstanceState) {
        autoRefresh();

        bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.item1:

                         break;
                    case R.id.item2:
                        break;
                    case R.id.item3:
                        break;
                }
                return false;
            }
        });
    }

    @Override
    public String getTitleText() {
        return "";
    }

    @Override
    public boolean onItemLongClick(BaseQuickAdapter adapter, View view, int position) {
        return false;
    }

    @Override
    public BaseQuickAdapter<Weather.HeWeather6Bean, BaseViewHolder> getAdapter() {
        return new BaseQuickAdapter<Weather.HeWeather6Bean, BaseViewHolder>(R.layout.item_text, mItems) {
            @Override
            protected void convert(BaseViewHolder helper, Weather.HeWeather6Bean item) {
                helper.setText(R.id.tv_item, item.getNow().getTmp()+helper.getLayoutPosition());
            }
        };
    }

    @Override
    public void loadData(final int page) {
        WeatherService.getInstance().getData("厦门", new ApiCallback<Weather>() {
            @Override
            public void onError(Throwable e) {
            }

            @Override
            public void onNext(Weather weather) {
                if (page== AFConstant.REFRESH_FIRST_PAGE){
                    mItems.clear();
                }
                for (int i = 0; i < 15; i++) {
                    mItems.addAll(weather.getHeWeather6());
                }
                refreshLoadComplete(isSuccess(weather.getHeWeather6()));
            }
        });
        refreshComplete();
    }
    @Override
    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
//        startActivity(mItems.get(position));
//        startActivity(CustomCaptureActivity.class);
    }

}
